class PublishSubscribePerfect {
  subscribes = new Map()
  getUUID (){
    return Date.now() + Math.random()
  }
  on(subscribe,callback) {
    const subscribeCallbacks = this.subscribes.get(subscribe) || new Map()
    const uuid = this.getUUID()
    subscribeCallbacks.set(uuid,callback)
    this.subscribes.set(subscribe,subscribeCallbacks)
    return uuid
  }
  remove(value) {
    const isSubscribe = this.subscribes.get(value)
    if(isSubscribe) {
      this.subscribes.delete(value)
    }else {
      for (const [subscribe,subscribeCallbacks] of this.subscribes) {
        for (const [uuid,callback] of subscribeCallbacks) {
          if(uuid === value) {
            subscribeCallbacks.delete(value)
          }
        }
      }
    }
  }
}